// Copyright (c) 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/**
*@describe:
*@author wfl19/Kristas
*@date 2021/08/27
 */

package api_test

import (
	"gitee.com/kristas/booting-go/framework"
	"gitee.com/kristas/booting-go/framework/core/statement/types"
	"gitee.com/kristas/booting-go/framework/web/resp"
	"gitee.com/kristas/booting-go/framework/web/rest"
	"net/http"
)

func init() {
	framework.Component(new(TestResponseWriteController))
}

type TestResponseWriteController struct {
	types.Controller `group:"/test/resp/write"`
	json             rest.GET `url:"/json" param:"[w response]"`
	xml              rest.GET `url:"/xml" param:"[w response]"`
	yaml             rest.GET `url:"/yaml" param:"[w response]"`
	text             rest.GET `url:"/text" param:"[w response]"`
	html             rest.GET `url:"/html" param:"[w response]"`
	redirect         rest.GET `url:"/redirect" param:"[w response,to query]"`
}

func (t *TestResponseWriteController) Json(w http.ResponseWriter) {
	resp.New(data).Write(w)
}

func (t *TestResponseWriteController) Xml(w http.ResponseWriter) {
	resp.New(data).ContentType(resp.ContentXMLHeaderValue).Write(w)
}

func (t *TestResponseWriteController) Yaml(w http.ResponseWriter) {
	resp.New(data).ContentType(resp.ContentYAMLHeaderValue).Write(w)
}

func (t *TestResponseWriteController) Text(w http.ResponseWriter) {
	resp.New(data).ContentType(resp.ContentTextHeaderValue).Write(w)
}

func (t *TestResponseWriteController) Html(w http.ResponseWriter) {
	resp.New(data).ContentType(resp.ContentHTMLHeaderValue).Write(w)
}

func (t *TestResponseWriteController) Redirect(w http.ResponseWriter, to string) {
	resp.Redirect(w, to)
}
